import struct

Key = 0x3b1ee5f6b3d99ff7

def decmap(data,Key):
    ret = b""
    for i in range(0x240):
        Key = (0x41C64E6D * Key + 0x3039) & 0xFFFFFFFFFFFFFFFF
        tmp = data[i] ^ (Key & 0xFF)
        ret += bytes([tmp]) #int转bytes！
    return ret

def update_key(x,y,Key):
    return Key + ((y*1427) + (x*7681) + (x * y + 5281)) & 0xFFFFFFFFFFFFFFFF

def check(mymapbit, key):
    tmpKey = key
    for i in range(8):
        for j in range(8):
            x = i + 0x41
            y = j + 0x31 
            coorpoint = 1<<(i*8 + j)
            if (coorpoint & mymapbit):
                print("X",end = "")
                tmpKey = update_key(x,y,tmpKey)
            else:
                print(" ",end = "")
        print()
    return tmpKey


with open("./data.bin","rb") as f:
    for i in range(99):
        data = f.read(0x240)
        ret = decmap(data,Key)

        mymapbit= struct.unpack_from("<Q",ret,0)[0]
        Key = struct.unpack_from("<Q",ret,0x10)[0]

        Key = check(mymapbit,Key)

        print("mymapbit->",hex(mymapbit))
        print("Key->",hex(Key))
        print("Mes->",ret[0x3E:])
        if Key == 0x216B6E75736C6C61:
            print("Over!")
            break;